/**
 *
 */
package org.insia.smartposse.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.insia.smartposse.form.SearchFreelancesForm;
import org.insia.smartposse.manager.list.FreelancesListManager;
import org.insia.smartposse.manager.list.SkillMapManager;

/**
 * @author cmougel
 *
 */
public class FreelancesAction extends DispatchAction {

	/**
	 * Define the default value By list
	 */
	@Override
	protected ActionForward dispatchMethod(ActionMapping map, ActionForm form, HttpServletRequest req, HttpServletResponse resp, String name) throws Exception {
		if (null == name){
			return list(map, form, req, resp);
		} else {
			return super.dispatchMethod(map, form, req, resp, name);
		}
	}

	/**
	 * See all projects closed
	 *
	 * @param map
	 * @param form
	 * @param req
	 * @param resp
	 * @return
	 * @throws Exception
	 */
	public ActionForward list(ActionMapping map, ActionForm form, HttpServletRequest req, HttpServletResponse resp) throws Exception {
		req.setAttribute("freelances", new FreelancesListManager());
		return map.findForward("list");
	}

	public ActionForward search(ActionMapping map, ActionForm form, HttpServletRequest req, HttpServletResponse resp) throws Exception {
		SearchFreelancesForm freelancesForm = (SearchFreelancesForm) form;
		req.setAttribute("freelances", new FreelancesListManager(freelancesForm));
		req.setAttribute("search", true);
		req.setAttribute("skillMap", new SkillMapManager().getMap());
		return map.findForward("list");
	}
}
